| Last name | First name | Email address | State | Started on | Completed | Time taken | Grade/60.00 | Question 1 | Response 1 | Right answer 1 | Question 2 | Response 2 | Right answer 2 | Question 3 | Response 3 | Right answer 3 | Question 4 | Response 4 | Right answer 4 | Question 5 | Response 5 | Right answer 5 | Question 6 | Response 6 | Right answer 6 | Question 7 | Response 7 | Right answer 7 | Question 8 | Response 8 | Right answer 8 | Question 9 | Response 9 | Right answer 9 | Question 10 | Response 10 | Right answer 10 | Question 11 | Response 11 | Right answer 11 | Question 12 | Response 12 | Right answer 12 | Question 13 | Response 13 | Right answer 13 | Question 14 | Response 14 | Right answer 14 | Question 15 | Response 15 | Right answer 15 | Question 16 | Response 16 | Right answer 16 | Question 17 | Response 17 | Right answer 17 |
|---|
| Semmens | Jake | 2317063@student.uwtsd.ac.uk | Finished | 12 January 2024 10:20 AM | 12 January 2024 11:52 AM | 1 hour 32 mins | 44.50 | Which variable type would be most suitable to store this value?
67.456 | %.3f (float) | float | Which variable type would be most suitable to store this value?
-6.23 | %.2f (float) | float | Which variable type would be most suitable to store this value?
-1.23 | %.2f (float) | float | Which variable type would be most suitable to store this value?
-26.1 | %.1f (float) | float | Which variable type would be most suitable to store this value?
B | %c (char) | char | Which variable type would be most suitable to store this value?
2 | %d (int) | int | What errors are present in the following code listing to calculate the area of a triangle? Write your answers below
1 #include <stdio.h>
2
3 void main()
4 {
5 char myname(7);
6 printf(Welcome to my program");
7
8 printf("Please enter your name: ");
9
10 scanf("%c", &myName);
11 printf("Welcome, %c", myName);
12 printf("I shall say hello to you 10 times: ")
13
14 for (x = 0; x < 9; x++);
15 {
16 printf("Hello");
17 }
18
19 } | Write your answers here (describe the errors found eg "Missing quotation mark on Line 4")
Missing quotation mark on line 6
myname on line 5 is has an lowercase 'n' while line 10 and 11 has an uppercase 'N'
There is no ; on line 12
#define _CRT_SECURE_NO_WARNINGS should be used to avoid errors with the scanf
'x' on line 14 is undeclared
| - | How many iterations does the following loop have?
FOR (I=4;I<8;I++)
{
PRINTF("HELLO");
} | 4 | 4 | How many iterations does the following loop have?
FOR (I=10;I>5;I--)
{
PRINTF("HELLO");
} | 5 | 5 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<8; x++)
{
total=total + x;
if(x==5)
{
total=0;
}
} | 13 | 13 | Given the following values x=5, y=3, z=12 is the statement below true or false?
X*Z > X*Y | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
X = Z-7 | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z != Y*4 | False | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z > Y*Y | False | True | THE SURFACE AREA OF A SPHERE IS CALCULATED USING THE FORMULA:
TASK:
WRITE A PROGRAM TO CALCULATE THE SURFACE AREA USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENT FOR _R__. R _SHOULD BE A POSITIVE NUMBER. YOU CAN SET PI TO 3.142.
PRINT THE AREA ON THE SCREEN TO 2 DECIMAL PLACES
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void main()
{
float radius{};
float area;
float pi = 3.142;
printf("Welcome to my program \n\n");
printf("Lets find the area of the sphere!\n\n");
printf("Please enter the radius: ");
scanf("%f", &radius);
while (radius < 1)
{
printf("Please enter a positive number: ");
scanf("%f", &radius);
}
area = 4 * pi * radius * radius;
printf("The surface area of the sphere is: %.2f ", area);
} | - | TASK:
A SALESMAN WANTS TO CALCULATE THE NUMBER OF MILES HE HAS COVERED IN THE LAST WORKING WEEK (MONDAY TO FRIDAY), AND ALSO THE NEW TOTAL MILEAGE FOR HIS CAR WHICH WAS 8600 MILES AT THE BEGINNING OF THE WEEK.
1. PROMPT THE USER TO ENTER THE FIVE MILEAGE FIGURES FOR THE WEEK INTO AN ARRAY.
2. PRINT EACH OF THE MILEAGE FIGURES ON THE SCREEN.
3. CALCULATE THE TOTAL MILEAGE FOR THE WEEK.
4. CALCULATE THE NEW MILEAGE FOR THE CAR (IT WAS 8600 AT THE START OF THE WEEK)
_USE LOOPS WHERE APPROPRIATE_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void main()
{
int mileage[5];
int newMileage;
int counter, i;
for (counter = 0; counter < 5; counter++)
{
printf("Please enter your five mileage figures for the week: ", counter);
scanf("%d", &mileage[counter]);
}
printf("\nThe mileage figures you have provided are: \n");
for (i = 0; i < 5; i++)
{
printf("%d miles\n", mileage[i]);
}
newMileage = 8600 + mileage[0] + mileage[1] + mileage[2] + mileage[3] + mileage[4];
printf("\nThe new mileage for your car is %d miles\n", newMileage);
} | - | TASK:
Write a function called _enterphone() to _allow the user to enter some UK office extension numbers (4 digits). The function should be called 3 times, and one number entered each time. Return the number entered back to the main program.
Print the numbers from the main program, then calculate and print the total cost of installation (£12.99 per number)
Include suitable validation of inputs.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void enterphone(void);
void main()
{
enterphone();
}
void enterphone()
{
int extensionNumber[3];
float numberPrice = 12.99;
float totalCost;
int counter, i;
for (counter = 0; counter < 3; counter++)
{
printf("Enter next your next extension number: ", counter);
scanf("%d", &extensionNumber[counter]);
}
printf("\nThe extension numbers entered were: ");
for (i = 0; i < 3; i++)
{
printf(" %d ", extensionNumber[i]);
}
totalCost = numberPrice * counter;
printf("\n\nTotal due is: \x9c%.2f \n\n", totalCost);
} | - |
| Jones | Max | 2305556@student.uwtsd.ac.uk | Finished | 12 January 2024 10:20 AM | 12 January 2024 11:28 AM | 1 hour 8 mins | 52.50 | Which variable type would be most suitable to store this value?
-1.23 | float | float | Which variable type would be most suitable to store this value?
-6.23 | float | float | Which variable type would be most suitable to store this value?
24 | int | int | Which variable type would be most suitable to store this value?
63000 | int | int | Which variable type would be most suitable to store this value?
2 | int | int | Which variable type would be most suitable to store this value?
4.192 | float | float | What errors are present in the following code listing to calculate the area of a room? Write your answers below
1 #include <stdio.h>
2
3 void main()
4 {
5 float widthRoom, heightRoom, total;
6 printf("Enter width: );
7 scanf("%d", &widthRoom);
8 printf("Enter height: ")
9 scanf("%d", &heightroom);
10 total = baseRoom / heightRoom;
11
12 print("The area of the room is", total);
13 } | On lines 7 and 9 the "%d" needs to become "%f"
On line 9 the variable "heightroom" needs a capital R to become "heightRoom"
On line 10 the variable "baseRoom" does not exist and needs to become "widthRoom"
Also on line 10 the "/" divides when it should be " * " to times the numbers together
On Line 12 the line needs to be changed from "print("The area of the room is", total);" to "printf("The area of the room is %.2f", total);" | - | How many iterations does the following loop have?
FOR (I=2;I<9;I=I+1)
{
PRINTF("HELLO");
} | 7 | 7 | How many iterations does the following loop have?
FOR (I=10;I>5;I--)
{
PRINTF("HELLO");
} | 5 | 5 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<8; x++)
{
total=total + x;
if(x==5)
{
total=0;
}
} | 3 | 13 | Given the following values x=5, y=3, z=12 is the statement below true or false?
X < Z/Y | False | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z < Y*X | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z = Y+8 | False | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
X = Z-7 | True | True | THE SURFACE AREA OF A SPHERE IS CALCULATED USING THE FORMULA:
TASK:
WRITE A PROGRAM TO CALCULATE THE SURFACE AREA USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENT FOR _R__. R _SHOULD BE A POSITIVE NUMBER. YOU CAN SET PI TO 3.142.
PRINT THE AREA ON THE SCREEN TO 2 DECIMAL PLACES
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void main()
{
float total, radius;
float pi = 3.142;
printf("What is the Radius: ");
scanf("%f", &radius);
while (radius < 0)
{
printf("Enter a positive Radius: ");
scanf("%f", &radius);
}
total = 4 * pi * (radius * radius);
printf("Total is %.2f", total);
} | - | TASK:
A SALESMAN WANTS TO CALCULATE THE NUMBER OF MILES HE HAS COVERED IN THE LAST WORKING WEEK (MONDAY TO FRIDAY), AND ALSO THE NEW TOTAL MILEAGE FOR HIS CAR WHICH WAS 8600 MILES AT THE BEGINNING OF THE WEEK.
1. PROMPT THE USER TO ENTER THE FIVE MILEAGE FIGURES FOR THE WEEK INTO AN ARRAY.
2. PRINT EACH OF THE MILEAGE FIGURES ON THE SCREEN.
3. CALCULATE THE TOTAL MILEAGE FOR THE WEEK.
4. CALCULATE THE NEW MILEAGE FOR THE CAR (IT WAS 8600 AT THE START OF THE WEEK)
_USE LOOPS WHERE APPROPRIATE_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void main()
{
int weekMiles[5];
int weeklyMileage=0;
int totalMileage = 8600;
for (int i = 0; i < 5; i++)
{
printf("Enter Miles of Day %d:", i+1);
scanf("%d", &weekMiles[i]);
weeklyMileage = weeklyMileage + weekMiles[i];
while (weekMiles[i] < 0)
{
printf("No Negatives!\n");
printf("Enter Miles of Day %d:", i + 1);
scanf("%d", &weekMiles[i]);
}
}
for (int i = 0; i < 5; i++)
{
printf("\nMiles for day %d: %d", i + 1,weekMiles[i]);
}
totalMileage = totalMileage + weeklyMileage;
printf("\nWeekly Mileage: %d", weeklyMileage);
printf("\nCars new total mileage: %d", totalMileage);
} | - | TASK:
WRITE A FUNCTION CALLED _ENTERIDNUMBER() TO _ALLOW THE USER TO ENTER THE ID NUMBER (5 DIGITS) OF THREE CONFERENCE DELEGATES. THE FUNCTION SHOULD BE CALLED 3 TIMES, ONCE FOR EACH OF THE CONFERENCE DELEGATES/ THE ID NUMBER ENTERED SHOULD BE RETURNED TO THE MAIN PROGRAM.
PRINT THE ID NUMBERS ENTERED FROM THE MAIN PROGRAM, THEN CALCULATE THE TOTAL BILL FOR ATTENDING THE CONFERENCE (£65 PER PERSON) AND PRINT IT ON THE SCREEN.
INCLUDE SUITABLE VALIDATION OF INPUTS.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include "header.h"
void main()
{
int delegatesIds[3];
int price;
for (int i = 0; i < 3; i++)
{
delegatesIds[i] = enteridnumber();
}
printf("\nThe delegates ID numbers are:");
for (int i = 0; i < 3; i++)
{
printf(" %d", delegatesIds[i]);
}
price = 65 * 3;
printf("\nTotal Price = %d", price);
}
#pragma once
int enteridnumber()
{
int i = 0;
int idNum;
printf("Enter ID: ");
scanf("%d", &idNum);
return idNum;
} | - |
| Thomas | Jay | 2305216@student.uwtsd.ac.uk | Finished | 12 January 2024 10:20 AM | 12 January 2024 12:19 PM | 1 hour 59 mins | 47.00 | Which variable type would be most suitable to store this value?
-6.23 | float | float | Which variable type would be most suitable to store this value?
BERT | String (Array of Char's) | string | Which variable type would be most suitable to store this value?
24 | Integer | int | Which variable type would be most suitable to store this value?
64995 | Integer | int | Which variable type would be most suitable to store this value?
4.192 | Float | float | Which variable type would be most suitable to store the following value?
JOHN | String (Array of Char's) | string | What errors are present in the following code listing to calculate the area of a triangle? Write your answers below
1 #include <stdio.h>
2
3 void main()
4 {
5 char myname(7);
6 printf(Welcome to my program");
7
8 printf("Please enter your name: ");
9
10 scanf("%c", &myName);
11 printf("Welcome, %c", myName);
12 printf("I shall say hello to you 10 times: ")
13
14 for (x = 0; x < 9; x++);
15 {
16 printf("Hello");
17 }
18
19 } | Missing line of code on line 2 should be #define _CRT_SECURE_NO_WARNINGS.
Missing quotation on line 7 should be 'printf("Welcome to my program");'
Incorrect placeholder on line 10 should be 'scanf("%s", &myName);' As we are looking for a string for a name not a character.
Incorrect variable name used on Line 10 and Line 11 should be "myname" with no capital.
Incorrect placeholder on line 11 should be 'printf("Welcome, %s", myName);
Missing quotation on line 11 should be 'printf("Welcome, %s", myName");
Missing semi-colon on line 12 should be 'printf("I shall say hello to you 10 times: ");'
Incorrect letter on line 14 should be 'for (i = 0; i > 10: i++);'
| - | How many iterations does the following loop have?
FOR (I=1;I<=8;I++)
{
PRINTF("HELLO");
} | 9 | 8 | How many iterations does the following loop have?
FOR (I=10;I>5;I--)
{
PRINTF("HELLO");
} | 6 | 5 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<10; x++)
{
total=total + x;
if(x==5)
{
total=0;
}
} | 30 | 30 | Given the following values x=5, y=3, z=12 is the statement below true or false?
X > Z/Y | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z = Y*4 | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z > Y*Y | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
X*Z > X*Y | True | True | THE SURFACE AREA OF A SPHERE IS CALCULATED USING THE FORMULA:
TASK:
WRITE A PROGRAM TO CALCULATE THE SURFACE AREA USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENT FOR _R__. R _SHOULD BE A POSITIVE NUMBER. YOU CAN SET PI TO 3.142.
PRINT THE AREA ON THE SCREEN TO 2 DECIMAL PLACES
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <time.h>]
void main(){
float radius;
float areaSphere;
printf("Please enter the radius of the sphere: \n");
scanf("%f", &radius);
//validation for the radius
while (radius < 0 || radius > 9999999999999) {
printf("\nSorry, cannot accept your number out of our range\n");
printf("\nPlease enter the radius of the sphere: \n");
scanf("%f", &radius);
}
//calculate the area of the sphere
areaSphere = 4*3.142*(radius*radius);
printf("The area of the sphere is: %.2f", areaSphere);
} | - | TASK:
A SALESMAN WANTS TO CALCULATE THE NUMBER OF MILES HE HAS COVERED IN THE LAST WORKING WEEK (MONDAY TO FRIDAY), AND ALSO THE NEW TOTAL MILEAGE FOR HIS CAR WHICH WAS 8600 MILES AT THE BEGINNING OF THE WEEK.
1. PROMPT THE USER TO ENTER THE FIVE MILEAGE FIGURES FOR THE WEEK INTO AN ARRAY.
2. PRINT EACH OF THE MILEAGE FIGURES ON THE SCREEN.
3. CALCULATE THE TOTAL MILEAGE FOR THE WEEK.
4. CALCULATE THE NEW MILEAGE FOR THE CAR (IT WAS 8600 AT THE START OF THE WEEK)
_USE LOOPS WHERE APPROPRIATE_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <time.h>]
void main(){
int milage[5];
int correct;
int total = 0;
int newMilage = 8600;
int Validation = 1;
for (int i = 0; i < 5; i++) {
printf("How many miles did you do for day %d? \n", i + 1);
scanf("%d", &milage[i]);
while (milage[i] < 0 || milage[i] > 100) {
printf("Error, out of bounds\n");
printf("How many miles did you do for day %d? \n", i + 1);
scanf("%d", &milage[i]);
}
}
for (int i = 0; i < 5; i++) {
printf("Miles completed on day %d = %d\n", i + 1, milage[i]);
total = total + milage[i];
}
//calculate the milage for the week
printf("\nThe total milage done for this week is %d\n", total);
//calculate the new milage of the car
while (Validation == 1) {
printf("Your milage was %d before this week, is this correct?\n 1 = Yes\n 0 = No\n\n", newMilage);
scanf("%d", &correct);
if (correct == 1) {
newMilage = newMilage + total;
printf("Great, your new milage on your car is %d", newMilage);
break;
}
else if (correct == 0) {
printf("Please input the correct milage for you car at the start of this week: \n");
scanf("%d", &newMilage);
newMilage = newMilage + total;
printf("Great, your new milage on your car is %d", newMilage);
break;
}
else {
printf("Error: Please type either 1 or 0\n");
}
}
} | - | TASK:
WRITE A FUNCTION CALLED _ENTERIDNUMBER() TO _ALLOW THE USER TO ENTER THE ID NUMBER (5 DIGITS) OF THREE CONFERENCE DELEGATES. THE FUNCTION SHOULD BE CALLED 3 TIMES, ONCE FOR EACH OF THE CONFERENCE DELEGATES/ THE ID NUMBER ENTERED SHOULD BE RETURNED TO THE MAIN PROGRAM.
PRINT THE ID NUMBERS ENTERED FROM THE MAIN PROGRAM, THEN CALCULATE THE TOTAL BILL FOR ATTENDING THE CONFERENCE (£65 PER PERSON) AND PRINT IT ON THE SCREEN.
INCLUDE SUITABLE VALIDATION OF INPUTS.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <time.h>]
int idnumber[3];
int i = 0;
void enteridnumber() {
printf("Enter next ID number: ");
scanf("%d", &idnumber[i]);
while (idnumber[i] <= 0 || idnumber[i] > 99999) {
printf("Error: Out of bounds\n");
printf("Enter next ID number: ");
scanf("%d", &idnumber[i]);
}
}
void main(){
for (i = 0; i < 3; i++) {
enteridnumber();
}
printf("\nThe delegates ID numbers are: ");
for (i = 0; i < 3; i++) {
printf("%.5d, ", idnumber[i]);
}
printf("\nThe total fee due is: 195.00 pounds\n");
} | - |
| Coleman | Matthew | 2306158@student.uwtsd.ac.uk | Finished | 12 January 2024 10:20 AM | 12 January 2024 12:20 PM | 1 hour 59 mins | 38.00 | Which variable type would be most suitable to store this value?
67.456 | Float | float | Which variable type would be most suitable to store this value?
-1.23 | Float | float | Which variable type would be most suitable to store this value?
BERT | String | string | Which variable type would be most suitable to store this value?
0.004 | Float | float | Which variable type would be most suitable to store this value?
CHRISTOPHER | String | string | Which variable type would be most suitable to store this value?
-6.23 | Float | float | What errors are present in the following code listing to calculate the area of a triangle? Write your answers below
1 #include <stdio.h>
2
3 void main()
4 {
5 char myname(7);
6 printf(Welcome to my program");
7
8 printf("Please enter your name: ");
9
10 scanf("%c", &myName);
11 printf("Welcome, %c", myName);
12 printf("I shall say hello to you 10 times: ")
13
14 for (x = 0; x < 9; x++);
15 {
16 printf("Hello");
17 }
18
19 } | Write your answers here (describe the errors found eg "Missing quotation mark on Line 4")
line 6 missing " at the start of printf.
line 10 and 11 "myname" variable has a lower case "n" but they are trying to reference it with a "N" so wont call it.
line 12 missing ";" at the end of the printf.
line 14 there is no value type given for x so the code won't compile as it doesn't know that its an integer.
line 10 and 11 are using %c instead of %s | - | How many iterations does the following loop have?
FOR (I=1;I<=8;I++)
{
PRINTF("HELLO");
} | 8 | 8 | How many iterations does the following loop have?
FOR (I=2;I<9;I=I+1)
{
PRINTF("HELLO");
} | 8 | 7 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<8; x++)
{
total=total + x;
if(x==5)
{
total=0;
}
} | 21 | 13 | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z = Y*4 | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
X < Z/Y | False | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z < Y*X | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
X==Y | False | False | The volume of a cone is calculated using the formula:
TASK:
WRITE A PROGRAM TO CALCULATE THE VOLUME USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENTS FOR _R _AND _H__. _BOTH_ R _AND_ H _SHOULD BE POSITIVE NUMBERS. YOU CAN SET PI TO 3.142
PRINT THE VOLUME ON THE SCREEN TO 2 DECIMAL PLACES
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
int main()
{
float volume, radius = -1, height =-1;
while (radius < 0 || height < 0) {
printf("\n\nplease enter the Radius and Height of the cone in that order in cm : ");
scanf("%f %f", &radius, &height);
if (radius < 0 || height < 0) {
printf("please enter valid numbers");
}
}
volume = (3.142 * (radius * radius)) * (height / 3);
printf("\n\nyour cone volume is : %.2f", volume);
} | - | TASK:
A SALESMAN WANTS TO CALCULATE THE NUMBER OF MILES HE HAS COVERED IN THE LAST WORKING WEEK (MONDAY TO FRIDAY), AND ALSO THE NEW TOTAL MILEAGE FOR HIS CAR WHICH WAS 8600 MILES AT THE BEGINNING OF THE WEEK.
1. PROMPT THE USER TO ENTER THE FIVE MILEAGE FIGURES FOR THE WEEK INTO AN ARRAY.
2. PRINT EACH OF THE MILEAGE FIGURES ON THE SCREEN.
3. CALCULATE THE TOTAL MILEAGE FOR THE WEEK.
4. CALCULATE THE NEW MILEAGE FOR THE CAR (IT WAS 8600 AT THE START OF THE WEEK)
_USE LOOPS WHERE APPROPRIATE_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int i;
float mf[5];
float Total = 8600;
for (i = 1; i < 6; i++) {
printf("\n\nplease enter your milage on day %d: ", i);
scanf("%f", &mf [i]);
}
printf("\nyour Milage figures for the past dates are: %.2f ,%.2f ,%.2f ,%.2f ,%.2f ", mf[1], mf[2], mf[3], mf[4], mf[5]);
Total = Total + mf[1] + mf[2] + mf[3] + mf[4] + mf[5];
printf("\nyour Total is : %.2f", Total);
} | - | TASK:
WRITE A FUNCTION CALLED _ENTERIDNUMBER() TO _ALLOW THE USER TO ENTER THE ID NUMBER (5 DIGITS) OF THREE CONFERENCE DELEGATES. THE FUNCTION SHOULD BE CALLED 3 TIMES, ONCE FOR EACH OF THE CONFERENCE DELEGATES/ THE ID NUMBER ENTERED SHOULD BE RETURNED TO THE MAIN PROGRAM.
PRINT THE ID NUMBERS ENTERED FROM THE MAIN PROGRAM, THEN CALCULATE THE TOTAL BILL FOR ATTENDING THE CONFERENCE (£65 PER PERSON) AND PRINT IT ON THE SCREEN.
INCLUDE SUITABLE VALIDATION OF INPUTS.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
int main()
{
char IDN[4][6];
int i,Total;
int a=0;
for (i = 1; i < 4; i++) {
printf("\nPlease enter your ID number: ");
scanf("%s", &IDN[i]);
while ((strlen(IDN[i]) > 5) || strlen(IDN[i]) < 5) {
printf("\nPlease enter a valid ID number: ");
scanf("%s", &IDN[i]);
}
a = a + 1;
}
printf("The Delagates IDs are: %s , %s , %s", IDN[1], IDN[2], IDN[3]);
Total = 65 * a;
printf("\n your Cost is: \x9C%d", Total);
} | - |
| Jonathan | Serena | 2306363@student.uwtsd.ac.uk | Finished | 12 January 2024 10:20 AM | 12 January 2024 12:19 PM | 1 hour 59 mins | 47.00 | Which variable type would be most suitable to store this value?
-26.1 | float | float | Which variable type would be most suitable to store this value?
-1.23 | float | float | Which variable type would be most suitable to store this value?
24 | int | int | Which variable type would be most suitable to store this value?
64995 | int | int | Which variable type would be most suitable to store this value?
63000 | int | int | Which variable type would be most suitable to store this value?
67.456 | float | float | What errors are present in the following code listing to calculate the area of a triangle? Write your answers below
1 #include <stdio.h>
2
3 void main()
4 {
5 char myname(7);
6 printf(Welcome to my program");
7
8 printf("Please enter your name: ");
9
10 scanf("%c", &myName);
11 printf("Welcome, %c", myName);
12 printf("I shall say hello to you 10 times: ")
13
14 for (x = 0; x < 9; x++);
15 {
16 printf("Hello");
17 }
18
19 } | Write your answers here (describe the errors found eg "Missing quotation mark on Line 4")
Line 5: Capital casing is not used to make code more readable and square brackets like this [7] should be used
Line 6 : Missing quotation mark
Line 10: Variable named does not match variable stored. Also should be %s not %c to print a string
Line 11: should be %s not %c to print a string
Line 12: Missing the ; at the end
line 14 : Should not have ; on the end and there is no variable stored for 'x'
| - | How many iterations does the following loop have?
FOR (I=10;I>5;I--)
{
PRINTF("HELLO");
} | 5 | 5 | How many iterations does the following loop have?
FOR (I=1;I<=8;I++)
{
PRINTF("HELLO");
} | 7 | 8 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<10; x++)
{
total=total + x;
if(x==5)
{
total=0;
}
} | 30 | 30 | Given the following values x=5, y=3, z=12 is the statement below true or false?
X==Y | False | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
X = Z-7 | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z = Y*4 | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
X < Z/Y | False | False | The volume of a cone is calculated using the formula:
TASK:
WRITE A PROGRAM TO CALCULATE THE VOLUME USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENTS FOR _R _AND _H__. _BOTH_ R _AND_ H _SHOULD BE POSITIVE NUMBERS. YOU CAN SET PI TO 3.142
PRINT THE VOLUME ON THE SCREEN TO 2 DECIMAL PLACES
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#define PI 3.142
void main()
{
float radius;
float height;
float volumeofCone;
printf("\nPlease enter base radius of cone: ");
scanf("%f", &radius);
while (radius <= 0)
{
printf("invalid. Cannot be 0 or less");
printf("\nTry again: ");
scanf("%f", &radius);
}
printf("\nPlease enter height of cone: ");
scanf("%f", &height);
while (height <= 0)
{
printf("invalid. Cannot be 0 or less");
printf("\nTry again: ");
scanf("%f", &height);
}
volumeofCone = PI * pow(radius, 2) * height / 3;
while (radius <= 0)
{
printf("invalid. Cannot be 0 or less");
printf("\nTry again: ");
scanf("%f", &radius);
}
printf("\nVolume of your cone is %.2f\n", volumeofCone);
} | - | TASK:
A SALESMAN WANTS TO CALCULATE THE NUMBER OF MILES HE HAS COVERED IN THE LAST WORKING WEEK (MONDAY TO FRIDAY), AND ALSO THE NEW TOTAL MILEAGE FOR HIS CAR WHICH WAS 8600 MILES AT THE BEGINNING OF THE WEEK.
1. PROMPT THE USER TO ENTER THE FIVE MILEAGE FIGURES FOR THE WEEK INTO AN ARRAY.
2. PRINT EACH OF THE MILEAGE FIGURES ON THE SCREEN.
3. CALCULATE THE TOTAL MILEAGE FOR THE WEEK.
4. CALCULATE THE NEW MILEAGE FOR THE CAR (IT WAS 8600 AT THE START OF THE WEEK)
_USE LOOPS WHERE APPROPRIATE_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
void main()
{
float miles[6];
char dayofWeek[5][10];
float totalMiles;
float differenceinMiles;
float newMiles;
float total;
for (int i = 0; i < 5; i++)
{
printf("Please enter the day of the week: ");
scanf("%s", &dayofWeek[i]);
for (int j = 0; dayofWeek[i][j] != \0; j++)
{
while (isdigit(dayofWeek[i][j]) != 0)
{
printf("Error. A day of the week cannot be a number. Please try again: ");
scanf("%s", &dayofWeek[i]);
}
}
printf("Please enter the number of miles done on this day: ");
while (scanf("%f", &miles[i]) != 1 )
{
printf("\nInvalid input. Please try again and enter number of miles done on this day: ");
scanf("%f", &miles[i]);
while (getchar() != \n);
}
printf("\n");
}
printf("\n\nDays enetered and mileage: \n");
for (int i = 0; i < 5; i++)
{
printf("%s %f\n", dayofWeek[i], miles[i]);
}
total = miles[0] + miles[1] + miles[2] + miles[3] + miles[4];
printf("\n\nTotal price of miles done this week is: %.2f", total);
newMiles = total + 8600;
printf("\nHere is the new mileage for your car %.2f", newMiles);
} | - | TASK:
WRITE A FUNCTION CALLED _ENTERMEASUREMENT() TO _ALLOW THE USER TO ENTER MEASUREMENTS FOR A PARCEL. THE USER WILL NEED TO ENTER THREE MEASUREMENTS, ONE EACH FOR THE LENGTH, WIDTH AND HEIGHT OF THE PARCEL. THE FUNCTION SHOULD BE CALLED 3 TIMES, ONCE FOR EACH OF THE MEASUREMENTS. EACH MEASUREMENT SHOULD BE RETURNED TO THE MAIN PROGRAM.
PRINT THE MEASUREMENTS ENTERED FROM MAIN(), THEN PRINT THE VOLUME OF THE PARCEL (LENGTH * WIDTH * HEIGHT)
INCLUDE SUITABLE VALIDATION OF INPUTS.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include "Header.h"
float calculatepackage();
void main()
{
float package;
printf("Lets work out the volume of your package:\n");
calculatepackage();
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX HEADER FILE XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#pragma once
#include <stdio.h>
float calculatepackage()
{
float total, length, width, height;
printf("\nPlease enter the length: ");
scanf("%f", &length);
printf("\nPlease enter the width: ");
scanf("%f", &width);
printf("\nPlease enter the height: ");
scanf("%f", &height);
printf("\nThe measurements you entered were: %.2f, %.2f, %.2f", length, width, height);
total = length * width * height;
printf("\nThe volume of your package is: %.2f\n\n", total);
return total;
} | - |
| Evans | Jacob | 2311160@student.uwtsd.ac.uk | Finished | 12 January 2024 10:20 AM | 12 January 2024 11:45 AM | 1 hour 24 mins | 46.00 | Which variable type would be most suitable to store this value?
2 | int | int | Which variable type would be most suitable to store this value?
4.192 | float | float | Which variable type would be most suitable to store this value?
B | char | char | Which variable type would be most suitable to store the following value?
56 | int | int | Which variable type would be most suitable to store this value?
0.004 | float | float | Which variable type would be most suitable to store this value?
G | char | char | What errors are present in the following code listing to calculate the area of a triangle? Write your answers below
1 #include <stdio.h>
2
3 void main()
4 {
5 char myname(7);
6 printf(Welcome to my program");
7
8 printf("Please enter your name: ");
9
10 scanf("%c", &myName);
11 printf("Welcome, %c", myName);
12 printf("I shall say hello to you 10 times: ")
13
14 for (x = 0; x < 9; x++);
15 {
16 printf("Hello");
17 }
18
19 } | Missing quotation line 6.
myname saved as a string, therefore line 10 and 11 should be "%s".
Missing variable (int) x.
Missing ; on line 12.
variable myName is not the same saved variable as myname on lines 10 and 11 (Capital letter N).
x<10 for line 14 if you wanted to print hello 10 times.
| - | How many iterations does the following loop have?
FOR (I=1;I<=8;I++)
{
PRINTF("HELLO");
} | 8 | 8 | How many iterations does the following loop have?
FOR (I=10;I>5;I--)
{
PRINTF("HELLO");
} | 5 | 5 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<8; x++)
{
total=total + x;
if(x==5)
{
total=0;
}
} | 3 | 13 | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z = Y*4 | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
X==Y | False | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z > Y*Y | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z = Y+8 | False | False | THE VOLUME OF A SPHERE IS CALCULATED USING THE FORMULA:
TASK:
WRITE A PROGRAM TO CALCULATE THE VOLUME USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENT FOR _R_. _R_ SHOULD NOT BE NEGATIVE. YOU MAY SET PI AS 3.142.
PRINT THE VOLUME ON THE SCREEN TO 2 DECIMAL PLACES.
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #define PI 3.142
float radius, volume;
printf("Please enter the radius of the sphere: ");
scanf("%f", &radius);
while (radius < 0)
{
printf("Please enter a valid radius: ");
scanf("%f", &radius);
}
volume = (radius * radius * radius) * PI*4/3;
printf("The volume of the sphere is: %.2f", volume); | - | TASK:
PROMPT THE USER TO ENTER FIVE RAINFALL MEASUREMENTS INTO AN ARRAY (IN MILLIMETRES). (EG 3.3, 5.0, 2.6 ETC)
AFTER THE MEASUREMENTS HAVE BEEN ENTERED, PRINT EACH OF THE VALUES ON THE SCREEN USING A LOOP.
AFTER THIS, FIND THE AVERAGE OF THE RAINFALL VALUES AND PRINT THE AVERAGE ON THE SCREEN TO ONE DECIMAL PLACE.
_USE LOOPS WHERE APPROPRIATE AND ADD SUITABLE VALIDATION OF INPUTS_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | int i;
float array[5], average=0;
for ( i = 0; i < 5; i++)
{
printf("Please enter the rainfall in millimetres: ");
scanf("%f", &array[i]);
while (array[i] < 0)
{
printf("Please enter 0 or larger:");
scanf("%f", &array[i]);
}
average = array[i] + average;
}
for (int j = 0; j < 5; j++)
{
printf("\nValues you have entered are: %.2fmm", array[j]);
}
average = (average / 5);
printf("\nThe average is rainfall: %.1fmm", average);
} | - | TASK:
WRITE A FUNCTION CALLED _ENTERMEASUREMENT() TO _ALLOW THE USER TO ENTER MEASUREMENTS FOR A PARCEL. THE USER WILL NEED TO ENTER THREE MEASUREMENTS, ONE EACH FOR THE LENGTH, WIDTH AND HEIGHT OF THE PARCEL. THE FUNCTION SHOULD BE CALLED 3 TIMES, ONCE FOR EACH OF THE MEASUREMENTS. EACH MEASUREMENT SHOULD BE RETURNED TO THE MAIN PROGRAM.
PRINT THE MEASUREMENTS ENTERED FROM MAIN(), THEN PRINT THE VOLUME OF THE PARCEL (LENGTH * WIDTH * HEIGHT)
INCLUDE SUITABLE VALIDATION OF INPUTS.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | include "volume.h"
void main()
{
float length, width, height;
printf("Please enter length: ");
scanf("%f", &length);
while (length <= 0)
{
printf("You cannot enter a negative measurement, try again: ");
scanf("%f", &length);
}
printf("Please enter width: ");
scanf("%f", &width);
while (width <= 0)
{
printf("You cannot enter a negative measurement, try again: ");
scanf("%f", &width);
}
printf("Please enter height: ");
scanf("%f", &height);
while (height <= 0)
{
printf("You cannot enter a negative measurement, try again: ");
scanf("%f", &height);
}
entermeasurement(length,width,height);
}
volume.h
entermeasurement(float length, float width, float height)
void entermeasurement(float length, float width, float height)
{
printf("\nLength entered: %.2f", length);
printf("\nWidth entered: %.2f", width);
printf("\nHeight entered: %.2f", height);
float volume = length * width * height;
printf("\nVolume = %.2f", volume);
return;
} | - |
| Mifsud | Sam | 2305369@student.uwtsd.ac.uk | Finished | 12 January 2024 10:20 AM | 12 January 2024 11:29 AM | 1 hour 9 mins | 49.00 | Which variable type would be most suitable to store this value?
2 | Integer | int | Which variable type would be most suitable to store this value?
-1.23 | Float | float | Which variable type would be most suitable to store this value?
CHRISTOPHER | String | string | Which variable type would be most suitable to store this value?
4.192 | Float | float | Which variable type would be most suitable to store the following value?
56 | Integer | int | Which variable type would be most suitable to store this value?
B | Character | char | What errors are present in the following code listing to do a calculation with two numbers and print the result on the screen? Write your answers in the box below. Line numbers are included for easy reference
1 #include <stdio.h>
2
3 void calculate(void);
4
5 void main()
6 {
7 int myValue1, myValue2;
8
9 printf("Welcome to my program );
10 scanf("%d", myValue1);
11 scanf("%d", myValue2);
12 calculate(myValue1, myValue2);
13 }
14
15 void calculate()
16 {
17 int total;
18 total = myValue1 + myValue2
19 printf("The total was %d", total);
20 return total;
21 } | _CRT_SECURE_NO_WARNINGS should be defined at the start of the program, before #include <stdio.h>
missing quotation mark before the closed bracket on line 9
line 10 needs an & symbol before myValue1
line 11 needs an & symbol before myValue2
myValue1 and myValue2 should be instantiated between the brackets on line 15 to allow values to be passed to them.
Missing semicolon at the end of line 18
Total is returned from a void function at line 20, the returned value is also unused. Either function type should be int or the return should be removed. | - | How many iterations does the following loop have?
FOR (I=2;I<9;I=I+1)
{
PRINTF("HELLO");
} | 7 | 7 | How many iterations does the following loop have?
FOR (I=1;I<6;I++)
{
PRINTF("HELLO");
} | 5 | 5 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<8; x++)
{
total=total + x;
if(x==5)
{
total=0;
}
} | 13 | 13 | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z != Y*4 | False | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
X = Z-7 | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
X > Z/Y | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z > Y*Y | True | True | THE VOLUME OF A SPHERE IS CALCULATED USING THE FORMULA:
TASK:
WRITE A PROGRAM TO CALCULATE THE VOLUME USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENT FOR _R_. _R_ SHOULD NOT BE NEGATIVE. YOU MAY SET PI AS 3.142.
PRINT THE VOLUME ON THE SCREEN TO 2 DECIMAL PLACES.
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
void main()
{
float volume = 0;
float radius = 0;
float pi = 3.14159265358;
int validationLoop = 1;
while (validationLoop == 1)
{
printf("What is the radius of the sphere?: ");
scanf("%f", &radius);
if (radius > 0)
{
break;
}
else
{
printf("Invalid input! radius must be higher than 0.\n");
}
}
volume = (4 * pi * pow(radius, 3)) / 3;
printf("The volume of the sphere is %.2f ", volume);
} | - | TASK:
A SALESMAN WANTS TO CALCULATE THE NUMBER OF MILES HE HAS COVERED IN THE LAST WORKING WEEK (MONDAY TO FRIDAY), AND ALSO THE NEW TOTAL MILEAGE FOR HIS CAR WHICH WAS 8600 MILES AT THE BEGINNING OF THE WEEK.
1. PROMPT THE USER TO ENTER THE FIVE MILEAGE FIGURES FOR THE WEEK INTO AN ARRAY.
2. PRINT EACH OF THE MILEAGE FIGURES ON THE SCREEN.
3. CALCULATE THE TOTAL MILEAGE FOR THE WEEK.
4. CALCULATE THE NEW MILEAGE FOR THE CAR (IT WAS 8600 AT THE START OF THE WEEK)
_USE LOOPS WHERE APPROPRIATE_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
void main()
{
int mileage[5];
int totalMilesWeek = 0;
int startMiles = 8600;
for (int i = 0; i < 5; i++)
{
printf("Please enter the number of miles the car did on day %d: ", i + 1);
scanf("%d", &mileage[i]);
}
printf("The mileages for each day this week were as follows:\n");
for (int i = 0; i < 5; i++)
{
printf("Day %d: %d miles\n", i, mileage[i]);
totalMilesWeek = totalMilesWeek + mileage[i];
}
printf("The total mileage this week was %d. \n", totalMilesWeek);
printf("The cars new mileage is %d. \n", totalMilesWeek + startMiles);
} | - | TASK:
Write a function called _enterphone() to _allow the user to enter some UK office extension numbers (4 digits). The function should be called 3 times, and one number entered each time. Return the number entered back to the main program.
Print the numbers from the main program, then calculate and print the total cost of installation (£12.99 per number)
Include suitable validation of inputs.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include "Header.h"
void main()
{
int tempExtension = 0;
int extensionArray[36];
int numberOfExtensions = 3;
float costOfExtension = 12.99;
for (int i = 0; i < 3; i++)
{
printf("Enter extension number for extension %d: ", i);
scanf("%d", &tempExtension);
extensionArray[i] = enterphone(tempExtension);
}
printf("The extension numbers you entered were %d, %d, %d.\n", extensionArray[0], extensionArray[1], extensionArray[2]);
printf("Total due is: %.2f", costOfExtension * numberOfExtensions);
}
#pragma once
int enterphone(int number)
{
return number;
} | - |
| Thomas | Kallem | 2304300@student.uwtsd.ac.uk | Finished | 12 January 2024 10:20 AM | 12 January 2024 12:17 PM | 1 hour 57 mins | 51.00 | Which variable type would be most suitable to store this value?
CHRISTOPHER | char | string | Which variable type would be most suitable to store this value?
24 | int | int | Which variable type would be most suitable to store this value?
2 | int | int | Which variable type would be most suitable to store this value?
-6.23 | float | float | Which variable type would be most suitable to store this value?
-1.23 | float | float | Which variable type would be most suitable to store this value?
4.192 | float | float | What errors are present in the following code listing to calculate the area of a triangle? Write your answers below
1 #include <stdio.h>
2
3 void main()
4 {
5 char myname(7);
6 printf(Welcome to my program");
7
8 printf("Please enter your name: ");
9
10 scanf("%c", &myName);
11 printf("Welcome, %c", myName);
12 printf("I shall say hello to you 10 times: ")
13
14 for (x = 0; x < 9; x++);
15 {
16 printf("Hello");
17 }
18
19 } | Write your answers here (describe the errors found eg "Missing quotation mark on Line 4")
requires a space between the " and % within the scanf within line 8.
requires a %s instead of %c within the printf of line 11.
the For loop on line 14 must be either x < 11 or x <= 10 instead of x < 9.
missing quotation on line 6.
missing semi-colon on line 12. | - | How many iterations does the following loop have?
FOR (I=1;I<=8;I++)
{
PRINTF("HELLO");
} | 7 iterations | 8 | How many iterations does the following loop have?
FOR (I=0;I<8;I++)
{
PRINTF("HELLO");
} | 7 iterations | 8 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<8; x++)
{
total=total + x;
if(x==5)
{
total=0;
}
} | 13 | 13 | Given the following values x=5, y=3, z=12 is the statement below true or false?
X==Y | False | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
X = Z-7 | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z < Y*X | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z != Y*4 | False | False | THE VOLUME OF A SPHERE IS CALCULATED USING THE FORMULA:
TASK:
WRITE A PROGRAM TO CALCULATE THE VOLUME USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENT FOR _R_. _R_ SHOULD NOT BE NEGATIVE. YOU MAY SET PI AS 3.142.
PRINT THE VOLUME ON THE SCREEN TO 2 DECIMAL PLACES.
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#define PI 3.142
void main()
{
float volume, radius;
printf("Please enter the radius of your circle: ");
scanf("%f", &radius);
while (radius < 0)
{
printf("Sorry, the number cannot be negative, please try again: ");
scanf("%f", &radius);
}
volume = 4 / 3 * ((pow(radius, 3) * PI));
printf("Here is the volume of your circle: %.2f", volume);
} | - | TASK:
A SALESMAN WANTS TO CALCULATE THE NUMBER OF MILES HE HAS COVERED IN THE LAST WORKING WEEK (MONDAY TO FRIDAY), AND ALSO THE NEW TOTAL MILEAGE FOR HIS CAR WHICH WAS 8600 MILES AT THE BEGINNING OF THE WEEK.
1. PROMPT THE USER TO ENTER THE FIVE MILEAGE FIGURES FOR THE WEEK INTO AN ARRAY.
2. PRINT EACH OF THE MILEAGE FIGURES ON THE SCREEN.
3. CALCULATE THE TOTAL MILEAGE FOR THE WEEK.
4. CALCULATE THE NEW MILEAGE FOR THE CAR (IT WAS 8600 AT THE START OF THE WEEK)
_USE LOOPS WHERE APPROPRIATE_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | void main()
{
int Mileage[5], total = 8600;
for (int i = 1; i < 6; i++)
{
printf("Please enter your mileage (%d): ", i);
scanf("%d", &Mileage[i-1]);
}
for (int i = 0; i < 5; i++)
{
total = total + Mileage[i];
}
printf("Your total mileage now is: %d", total);
} | - | TASK:
Write a function called _enterphone() to _allow the user to enter some UK office extension numbers (4 digits). The function should be called 3 times, and one number entered each time. Return the number entered back to the main program.
Print the numbers from the main program, then calculate and print the total cost of installation (£12.99 per number)
Include suitable validation of inputs.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define NUM 12.99
#include "Header.h"
void main()
{
int extensionNumber[3];
float total = 0;
extensionNumber[0] = enterphone();
extensionNumber[1] = enterphone();
extensionNumber[2] = enterphone();
printf("The extension numbers entered were:\n");
for (int i = 0; i < 3; i++)
{
printf("%d ", extensionNumber[i]);
}
total = 3 * NUM;
printf("\nTotal due is: \x9c%.2f", total);
}
\\Header file
int enterphone()
{
char UserEnteredExtensionNumber[20];
int extensionNumber;
printf("Enter extension number: ");
scanf("%s", &UserEnteredExtensionNumber);
extensionNumber = atoi(UserEnteredExtensionNumber);
int x = floor(log10(extensionNumber)) + 1; //counts the length of a number, For example: 5000 = 4, 400 = 3, 5 = 1 etc.
while (x != 4)
{
printf("invalid, please try again: ");
scanf("%s", &UserEnteredExtensionNumber);
extensionNumber = atoi(UserEnteredExtensionNumber);
x = floor(log10(extensionNumber)) + 1;
}
return extensionNumber;
} | - |
| Hopkins | Ryan | 2221956@student.uwtsd.ac.uk | Finished | 12 January 2024 10:20 AM | 12 January 2024 11:20 AM | 59 mins 56 secs | 56.50 | Which variable type would be most suitable to store this value?
-1.23 | float | float | Which variable type would be most suitable to store this value?
4.192 | float | float | Which variable type would be most suitable to store the following value?
JOHN | string / char array | string | Which variable type would be most suitable to store this value?
B | char | char | Which variable type would be most suitable to store this value?
BERT | string / char array | string | Which variable type would be most suitable to store this value?
67.456 | float | float | What errors are present in the following code listing to calculate the area of a room? Write your answers below
1 #include <stdio.h>
2
3 void main()
4 {
5 float widthRoom, heightRoom, total;
6 printf("Enter width: );
7 scanf("%d", &widthRoom);
8 printf("Enter height: ")
9 scanf("%d", &heightroom);
10 total = baseRoom / heightRoom;
11
12 print("The area of the room is", total);
13 } | Write your answers here (describe the errors found eg "Missing quotation mark on Line 4")
line 0: for any scanf function to run you need to define _CRT_SECURE_NO_WARNINGS
line 6: missing speech marks to end the printf statement.
line 8: Missing semi colon at the end of the printf statement.
line 9: heightroom variable differs from previously defined heightRoom, therefore not storing anything inside of heightRoom
line 10: baseRoom is not a defined variable, the correct variable use should have been widthRoom.
line 10: calculation for area should have been widthRoom* heightRoom
line 12: missing f on the end of printf
line 12: missing %f when calling a variable inside the print statement | - | How many iterations does the following loop have?
FOR (I=1;I<6;I++)
{
PRINTF("HELLO");
} | 5 | 5 | How many iterations does the following loop have?
FOR (I=10;I>5;I--)
{
PRINTF("HELLO");
} | 5 | 5 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<8; x++)
{
total=total + x;
if(x==5)
{
total=0;
}
} | 13 | 13 | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z = Y*4 | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
X*Z > X*Y | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
X > Z/Y | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z < Y*X | True | True | The volume of a cone is calculated using the formula:
TASK:
WRITE A PROGRAM TO CALCULATE THE VOLUME USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENTS FOR _R _AND _H__. _BOTH_ R _AND_ H _SHOULD BE POSITIVE NUMBERS. YOU CAN SET PI TO 3.142
PRINT THE VOLUME ON THE SCREEN TO 2 DECIMAL PLACES
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
float PI = 3.142;
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <Windows.h>
void main()
{
float r, h;
char userStore[64];
printf("enter the radius of the cone: \n \n \t User: ");
scanf("%s", &userStore);
r = strtof(userStore, FALSE); // stops the user from entering characters aswell as leaving blank
while (r <= 0)
{
printf("enter the radius of the cone: \n \n \t User: ");
scanf("%s", &userStore);
r = strtof(userStore, FALSE);
}
printf("enter the height of the cone: \n \n \t User: ");
scanf("%s", &userStore);
h = strtof(userStore, FALSE);// stops the user from entering characters aswell as leaving blank
while (h <= 0)
{
printf("enter the height of the cone: \n \n \t User: ");
scanf("%s", &userStore);
h = strtof(userStore, FALSE);
}
float volume = PI * (pow(r, 2)) * (h / 3);
printf("the volume of the cone is: \n\n \t Total: %.2f", volume);
} | - | TASK:
A SALESMAN WANTS TO CALCULATE THE NUMBER OF MILES HE HAS COVERED IN THE LAST WORKING WEEK (MONDAY TO FRIDAY), AND ALSO THE NEW TOTAL MILEAGE FOR HIS CAR WHICH WAS 8600 MILES AT THE BEGINNING OF THE WEEK.
1. PROMPT THE USER TO ENTER THE FIVE MILEAGE FIGURES FOR THE WEEK INTO AN ARRAY.
2. PRINT EACH OF THE MILEAGE FIGURES ON THE SCREEN.
3. CALCULATE THE TOTAL MILEAGE FOR THE WEEK.
4. CALCULATE THE NEW MILEAGE FOR THE CAR (IT WAS 8600 AT THE START OF THE WEEK)
_USE LOOPS WHERE APPROPRIATE_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
void main() {
// array of five, print out the new milage for his car, car mileage starts at 8600, print out the mileage on the screem, calculate the new mileage for the week
int userMileage[6];
char userStore[64];
for (int i = 0; i < 5; i++)
{
system("cls");
printf("please enter the amount of miles for day %d:\n\n \t User:", i);
scanf("%s", &userStore);
userMileage[i] = strtod(userStore, FALSE);
while (userMileage[i] <= 0)
{
printf("amount not accepted, please enter a number.\n \nplease enter the amount of miles for day %d: \n \n \t User: ", i);
scanf("%s", &userStore);
userMileage[i] = strtod(userStore, FALSE);
}
}
int totalMileage = 8600;
printf("the total Mileage at the start of the week was: %d\n\n", totalMileage);
for (int i = 0; i < 5; i++)
{
printf("the total mileage you have inputted \n\tfor day %d: %d\n", i, userMileage[i]);
totalMileage = totalMileage + userMileage[i];
}
printf("\n \nwhich leaves the total mileage at the end of the week at %d", totalMileage);
} | - | TASK:
WRITE A FUNCTION CALLED _ENTERIDNUMBER() TO _ALLOW THE USER TO ENTER THE ID NUMBER (5 DIGITS) OF THREE CONFERENCE DELEGATES. THE FUNCTION SHOULD BE CALLED 3 TIMES, ONCE FOR EACH OF THE CONFERENCE DELEGATES/ THE ID NUMBER ENTERED SHOULD BE RETURNED TO THE MAIN PROGRAM.
PRINT THE ID NUMBERS ENTERED FROM THE MAIN PROGRAM, THEN CALCULATE THE TOTAL BILL FOR ATTENDING THE CONFERENCE (£65 PER PERSON) AND PRINT IT ON THE SCREEN.
INCLUDE SUITABLE VALIDATION OF INPUTS.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | // Header file is "RyansHeader.h"
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include "RyansHeader.h"
void main() {
int delegateID[4], totalCost = 0; for (int i = 0; i < 3; i++)
{
delegateID[i] = enteridnumber();
}
for (int i = 0; i < 3; i++)
{
if (delegateID[i] > 0)
{
totalCost = totalCost + 65;
}
}
printf("the total cost is \x9c%d", totalCost);
}
#pragma once
int enteridnumber() {
char userStore[64];
printf("please enter a delegate ID ");
scanf("%s", &userStore);
int DelegateID = strtod(userStore, FALSE);
while (DelegateID <= 9999 || DelegateID > 99999)
{
system("cls");
printf("please enter a delegate ID\n these are five numbers long\n \n \t User:");
scanf("%s", &userStore);
DelegateID = strtod(userStore, FALSE);
}
return DelegateID
;
} | - |
| Sureshkumar | Sohaan | 2221048@student.uwtsd.ac.uk | Finished | 12 January 2024 10:20 AM | 12 January 2024 12:20 PM | 1 hour 59 mins | 49.00 | Which variable type would be most suitable to store the following value?
JOHN | char[] | string | Which variable type would be most suitable to store the following value?
56 | int | int | Which variable type would be most suitable to store this value?
67.456 | float | float | Which variable type would be most suitable to store this value?
CHRISTOPHER | char[] | string | Which variable type would be most suitable to store this value?
-6.23 | float | float | Which variable type would be most suitable to store this value?
BERT | char[] | string | What errors are present in the following code listing to do a calculation with two numbers and print the result on the screen? Write your answers in the box below. Line numbers are included for easy reference
1 #include <stdio.h>
2
3 void calculate(void);
4
5 void main()
6 {
7 int myValue1, myValue2;
8
9 printf("Welcome to my program );
10 scanf("%d", myValue1);
11 scanf("%d", myValue2);
12 calculate(myValue1, myValue2);
13 }
14
15 void calculate()
16 {
17 int total;
18 total = myValue1 + myValue2
19 printf("The total was %d", total);
20 return total;
21 } | missing the quotations on line 9
Lines 10 and 11 are missing the "address of operator" (&)
On line 15, the parameters are missing which is being called in line 12.
line 18 has a missing semicolon (;)
the calculate function should be declared by the data type int, and the return statement should be at the end
The function prototype should be declared as such: void calculate(int myValue 1, int myValue ); | - | How many iterations does the following loop have?
FOR (I=10;I>5;I--)
{
PRINTF("HELLO");
} | 6 | 5 | How many iterations does the following loop have?
FOR (I=0;I<8;I++)
{
PRINTF("HELLO");
} | 9 | 8 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<9; x++)
{
total=total+x;
if(x==5)
{
total=0;
}
} | 0 | 21 | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z = Y+8 | True | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
X*Z > X*Y | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z > Y*Y | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
X==Y | False | False | THE VOLUME OF A SQUARE-BASED PYRAMID IS CALCULATED USING THE FORMULA:
TASK:
WRITE A PROGRAM TO CALCULATE THE VOLUME USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENTS FOR _A_ AND _H__. _BOTH_ A_ AND_ H _SHOULD BE POSITIVE NUMBERS.
PRINT THE VOLUME ON THE SCREEN TO 2 DECIMAL PLACES
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #include <stdio.h>
void main() {
float Base_Length, Height;
printf("Welcome !\nLets calculate the Volume of your pyramid \n");
while (1) {
printf("Firstly, Please enter the base length of your pyramid: ");
scanf("%f", &Base_Length);
if (Base_Length >= 0){
break;
}
else {
printf("Input Invalid ! Please enter a positive value for base length\n");
}
}
while (1){
printf("Perfect!\n Now Please enter the Height of your pyramid: ");
scanf("%f", &Height);
if (Height >= 0) {
break;
} else {
printf("Input Invalid ! Please enter a positive value for Height\n");
}
}
float Volume_P = (Base_Length * Base_Length * Height) / 3.0;
printf("Based on your Inputs,\nThe volume of the pyramid = %.2f\n", Volume_P);
} | - | TASK:
PROMPT THE USER TO ENTER FIVE RAINFALL MEASUREMENTS INTO AN ARRAY (IN MILLIMETRES). (EG 3.3, 5.0, 2.6 ETC)
AFTER THE MEASUREMENTS HAVE BEEN ENTERED, PRINT EACH OF THE VALUES ON THE SCREEN USING A LOOP.
AFTER THIS, FIND THE AVERAGE OF THE RAINFALL VALUES AND PRINT THE AVERAGE ON THE SCREEN TO ONE DECIMAL PLACE.
_USE LOOPS WHERE APPROPRIATE AND ADD SUITABLE VALIDATION OF INPUTS_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | #include <stdio.h>
void main() {
float RF_Measurements[5], Total_RF = 0;
for (int i = 0; i < 5; ++i){
printf("Please Input Rainfall Measurment #%d (in mm): ", i + 1);
scanf("%f", &RF_Measurements[i]);
while (RF_Measurements[i] < 0){
printf("Input Invalid ! Please enter a POSITIVE Value Please: \n");
printf("Please Input Rainfall Measurment #%d again (in mm): ", i + 1);
scanf("%f", &RF_Measurements[i]);
}
Total_RF += RF_Measurements[i];
}
printf("\nRainfall Measurements Inputted:\n");
for (int i = 0; i < 5; ++i){
printf("%.1f ", RF_Measurements[i]);
}
float Avg_RF = Total_RF / 5;
printf("\nThe Average Rainfall Based on inputed Measurements: %.1f\n", Avg_RF);
} | - | TASK:
WRITE A FUNCTION CALLED _ENTERMEASUREMENT() TO _ALLOW THE USER TO ENTER MEASUREMENTS FOR A PARCEL. THE USER WILL NEED TO ENTER THREE MEASUREMENTS, ONE EACH FOR THE LENGTH, WIDTH AND HEIGHT OF THE PARCEL. THE FUNCTION SHOULD BE CALLED 3 TIMES, ONCE FOR EACH OF THE MEASUREMENTS. EACH MEASUREMENT SHOULD BE RETURNED TO THE MAIN PROGRAM.
PRINT THE MEASUREMENTS ENTERED FROM MAIN(), THEN PRINT THE VOLUME OF THE PARCEL (LENGTH * WIDTH * HEIGHT)
INCLUDE SUITABLE VALIDATION OF INPUTS.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | #include <stdio.h>
float EnterMeasurement(const char* );
int main() {
float Parcel_length_, Parcel_width, Parcel_height;
Parcel_length_ = EnterMeasurement("length");
Parcel_width = EnterMeasurement("width");
Parcel_height = EnterMeasurement("height");
printf("\nAll Measurements which you have Entered: \n");
printf("Length of The Parcel: %.2f\n", Parcel_length_);
printf("Width of The Parcel: %.2f\n", Parcel_width);
printf("Height of Parcel: %.2f\n", Parcel_height);
float Parcel_Volume = Parcel_length_ * Parcel_width * Parcel_height;
printf("\nThe Volume of the parcel: %.2lf\n", Parcel_Volume);
return 0;
}
float EnterMeasurement(const char* Measurement_Type) {
float P_measurement;
while(1) {
printf("Please enter the %s of the parcel : ", Measurement_Type);
if (scanf("%f", &P_measurement) == 1 && P_measurement > 0) {
return P_measurement;
} else {
printf("Input Invalid ! Please Enter a Positive Value :\n");
}
}
} | - |
| Plumley | Rose | 2218443@student.uwtsd.ac.uk | Finished | 12 January 2024 10:20 AM | 12 January 2024 11:15 AM | 54 mins 33 secs | 55.00 | Which variable type would be most suitable to store this value?
24 | int | int | Which variable type would be most suitable to store the following value?
JOHN | char (array) | string | Which variable type would be most suitable to store this value?
63000 | int | int | Which variable type would be most suitable to store this value?
CHRISTOPHER | char (array) | string | Which variable type would be most suitable to store this value?
-1.23 | float | float | Which variable type would be most suitable to store this value?
2 | int | int | What errors are present in the following code listing to calculate the area of a triangle? Write your answers below
1 #include <stdio.h>
2
3 void main()
4 {
5 char myname(7);
6 printf(Welcome to my program");
7
8 printf("Please enter your name: ");
9
10 scanf("%c", &myName);
11 printf("Welcome, %c", myName);
12 printf("I shall say hello to you 10 times: ")
13
14 for (x = 0; x < 9; x++);
15 {
16 printf("Hello");
17 }
18
19 } | Write your answers here (describe the errors found eg "Missing quotation mark on Line 4")
No #define _CRT_SECURE_NO_WARNINGS at the top. Scanf() won't work otherwise.
Line 5 - Need square brackets instead of regular ones for a char array.
Line 6 - Missing quotation marks before Welcome.
Line 10 - Need %s instead of %c to enter a string. Even assuming you want a single character, would need to be scanf(" %c", &myName);
Line 14 - Need to declare x as an int in the for loop e.g.: for (int x = 0; x < 9; x++) or declare x variable earlier in the code.
Line 14 - Semicolon added at the end, should be removed.
Line 14 - To say Hello 10 times, x should be < 11 in for loop. e.g.: for (int x = 0; x < 11; x++)
| - | How many iterations does the following loop have?
FOR (I=0;I<=8;I++)
{
PRINTF("HELLO");
} | 8 | 9 | How many iterations does the following loop have?
FOR (I=4;I<8;I++)
{
PRINTF("HELLO");
} | 4 | 4 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<9; x++)
{
total=total+x;
if(x==5)
{
total=0;
}
} | 21 | 21 | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z = Y+8 | False | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z != Y*4 | False | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z > Y*Y | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z < Y*X | True | True | THE VOLUME OF A SQUARE-BASED PYRAMID IS CALCULATED USING THE FORMULA:
TASK:
WRITE A PROGRAM TO CALCULATE THE VOLUME USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENTS FOR _A_ AND _H__. _BOTH_ A_ AND_ H _SHOULD BE POSITIVE NUMBERS.
PRINT THE VOLUME ON THE SCREEN TO 2 DECIMAL PLACES
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
void main()
{
float pyramidBaseLength, pyramidHeight, pyramidVolume;
printf("Please enter the length of the base of your pyramid: ");
scanf("%f", &pyramidBaseLength);
while (pyramidBaseLength <= 0)
{
printf("This program will only accept positive values.\n");
printf("Please enter the length of the base of your pyramid: ");
scanf("%f", &pyramidBaseLength);
}
printf("\nPlease enter the height of your pyramid: ");
scanf("%f", &pyramidHeight);
while (pyramidHeight <= 0)
{
printf("This program will only accept positive values.\n");
printf("\nPlease enter the height of your pyramid: ");
scanf("%f", &pyramidHeight);
}
pyramidVolume = pow(pyramidBaseLength, 2) * (pyramidHeight / 3);
printf("\nThe volume of your pyramid is: %.2f (2d.p.)", pyramidVolume);
} | - | TASK:
A SALESMAN WANTS TO CALCULATE THE NUMBER OF MILES HE HAS COVERED IN THE LAST WORKING WEEK (MONDAY TO FRIDAY), AND ALSO THE NEW TOTAL MILEAGE FOR HIS CAR WHICH WAS 8600 MILES AT THE BEGINNING OF THE WEEK.
1. PROMPT THE USER TO ENTER THE FIVE MILEAGE FIGURES FOR THE WEEK INTO AN ARRAY.
2. PRINT EACH OF THE MILEAGE FIGURES ON THE SCREEN.
3. CALCULATE THE TOTAL MILEAGE FOR THE WEEK.
4. CALCULATE THE NEW MILEAGE FOR THE CAR (IT WAS 8600 AT THE START OF THE WEEK)
_USE LOOPS WHERE APPROPRIATE_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void main()
{
int mileage[5];
char weekDays[5][20] = { {"Monday"},{"Tuesday"}, {"Wednesday"}, {"Thursday"}, {"Friday"} };
int carMileage = 8600;
int totalMileage = 0;
for (int i = 0; i < 5; i++)
{
printf("Enter the miles driven on %s: ", weekDays[i]);
scanf("%d", &mileage[i]);
}
totalMileage = totalMileage + carMileage;
for (int i = 0; i < 5; i++)
{
totalMileage = totalMileage + mileage[i];
}
printf("\nYour total mileage is: %d\n", totalMileage);
} | - | TASK:
Write a function called _enterphone() to _allow the user to enter some UK office extension numbers (4 digits). The function should be called 3 times, and one number entered each time. Return the number entered back to the main program.
Print the numbers from the main program, then calculate and print the total cost of installation (£12.99 per number)
Include suitable validation of inputs.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include "rose.h"
void main()
{
int extensionNumber1;
int extensionNumber2;
int extensionNumber3;
float installationCost = 12.99;
extensionNumber1 = enterphone();
extensionNumber2 = enterphone();
extensionNumber3 = enterphone();
printf("\nThe extension numbers entered were: %d %d %d\n", extensionNumber1, extensionNumber2, extensionNumber3);
installationCost = installationCost * 3;
printf("Total cost of installation: %.2f\n", installationCost);
}
---------------Header File "rose.h" Below---------------
#pragma once
int enterphone()
{
int extensionNumber;
printf("Please enter the next extension number: ");
scanf("%d", &extensionNumber);
while (extensionNumber <= 0 || extensionNumber > 9999)
{
printf("Invalid input!\n");
printf("Please re-enter the extension number: ");
scanf("%d", &extensionNumber);
}
return extensionNumber;
} | - |
| James-Machin | Jacob | 2304400@student.uwtsd.ac.uk | Finished | 12 January 2024 10:20 AM | 12 January 2024 12:50 PM | 2 hours 29 mins | 30.00 | Which variable type would be most suitable to store this value?
2 | Int | int | Which variable type would be most suitable to store this value?
4.192 | float | float | Which variable type would be most suitable to store this value?
B | char | char | Which variable type would be most suitable to store this value?
-6.23 | float | float | Which variable type would be most suitable to store this value?
64995 | int | int | Which variable type would be most suitable to store this value?
67.456 | float | float | What errors are present in the following code listing to calculate the area of a triangle? Write your answers below
1 #include <stdio.h>
2
3 void main()
4 {
5 char myname(7);
6 printf(Welcome to my program");
7
8 printf("Please enter your name: ");
9
10 scanf("%c", &myName);
11 printf("Welcome, %c", myName);
12 printf("I shall say hello to you 10 times: ")
13
14 for (x = 0; x < 9; x++);
15 {
16 printf("Hello");
17 }
18
19 } | There is a syntax error on line 6 its missing the quotation mark it should be
printf("Welcome to my program");
instead of
printf(Welcome to my program"); | - | How many iterations does the following loop have?
FOR (I=1;I<=8;I++)
{
PRINTF("HELLO");
} | 7 | 8 | How many iterations does the following loop have?
FOR (I=0;I<8;I++)
{
PRINTF("HELLO");
} | 8 | 8 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<10; x++)
{
total=total + x;
if(x==5)
{
total=0;
}
} | 5 | 30 | Given the following values x=5, y=3, z=12 is the statement below true or false?
X < Z/Y | True | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z = Y+8 | True | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z < Y*X | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z = Y*4 | True | True | THE SURFACE AREA OF A SPHERE IS CALCULATED USING THE FORMULA:
TASK:
WRITE A PROGRAM TO CALCULATE THE SURFACE AREA USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENT FOR _R__. R _SHOULD BE A POSITIVE NUMBER. YOU CAN SET PI TO 3.142.
PRINT THE AREA ON THE SCREEN TO 2 DECIMAL PLACES
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define M_PI 3.14159265358979323846.
void main()
{
int i;
int r = 4;
float pi = 3.14159265358979323846;
float circle;
printf("enter radius ");
scanf("%f", &circle);
circle = 4 * pi * (r * r);
printf("The Area of the circle is %.f",circle + r);
} | - | TASK:
PROMPT THE USER TO ENTER FIVE RAINFALL MEASUREMENTS INTO AN ARRAY (IN MILLIMETRES). (EG 3.3, 5.0, 2.6 ETC)
AFTER THE MEASUREMENTS HAVE BEEN ENTERED, PRINT EACH OF THE VALUES ON THE SCREEN USING A LOOP.
AFTER THIS, FIND THE AVERAGE OF THE RAINFALL VALUES AND PRINT THE AVERAGE ON THE SCREEN TO ONE DECIMAL PLACE.
_USE LOOPS WHERE APPROPRIATE AND ADD SUITABLE VALIDATION OF INPUTS_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define M_PI 3.14159265358979323846.
void main()
{
float rainfall[5] ;
int measurements;
float total;
for (int i = 0; i < 6; i++)
{
printf("\nEnter measurement ");
scanf("%s", &measurements);
}
total = measurements + rainfall[5];
printf("\n The Total Measurements is: \n");
for (int i = 0; i < 6; i++)
{
printf("%.2f\n", total = rainfall[i]);
}
} | - | TASK:
WRITE A FUNCTION CALLED _ENTERIDNUMBER() TO _ALLOW THE USER TO ENTER THE ID NUMBER (5 DIGITS) OF THREE CONFERENCE DELEGATES. THE FUNCTION SHOULD BE CALLED 3 TIMES, ONCE FOR EACH OF THE CONFERENCE DELEGATES/ THE ID NUMBER ENTERED SHOULD BE RETURNED TO THE MAIN PROGRAM.
PRINT THE ID NUMBERS ENTERED FROM THE MAIN PROGRAM, THEN CALCULATE THE TOTAL BILL FOR ATTENDING THE CONFERENCE (£65 PER PERSON) AND PRINT IT ON THE SCREEN.
INCLUDE SUITABLE VALIDATION OF INPUTS.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void main()
{
int idnumber[3];
float price;
for (int i = 0; i < 3; i++)
{
printf("\nEnter ID Number ");
scanf("%f", &idnumber);
}
for (int i = 0; i < 3; i++)
{
printf("The delegates ID numbers are: %.f");
}
price + 65;
printf("\nThe total fue due is: %f", &price);
} | - |
| Nicklin | Jacob | 2305180@student.uwtsd.ac.uk | Finished | 12 January 2024 10:20 AM | 12 January 2024 12:18 PM | 1 hour 57 mins | 41.50 | Which variable type would be most suitable to store this value?
-26.1 | float | float | Which variable type would be most suitable to store this value?
24 | integer | int | Which variable type would be most suitable to store the following value?
56 | integer | int | Which variable type would be most suitable to store the following value?
JOHN | char[ ] | string | Which variable type would be most suitable to store this value?
-6.23 | float | float | Which variable type would be most suitable to store this value?
CHRISTOPHER | char[] | string | What errors are present in the following code listing to calculate the area of a triangle? Write your answers below
1 #include <stdio.h>
2
3 void main()
4 {
5 char myname(7);
6 printf(Welcome to my program");
7
8 printf("Please enter your name: ");
9
10 scanf("%c", &myName);
11 printf("Welcome, %c", myName);
12 printf("I shall say hello to you 10 times: ")
13
14 for (x = 0; x < 9; x++);
15 {
16 printf("Hello");
17 }
18
19 } | On line 8 There is a missing opening quotation mark on line 8.
line 14 should be (x = 0; x < 10; x++) since it will only print 9 times otherwise.
line 14 also doesn't need the semi colon for the closing bracket since the line of code is creating the "for" statement's rule.
x is undefined on line 14 and should be given an integer value beforehand.
line 1 should be: '#define _CRT_SECURE_NO_WARNINGS' in order to avoid scanf problems
line 5 has not capitalised "myName" the same way its used on line 10 and 11, so the value is undefined.
| - | How many iterations does the following loop have?
FOR (I=10;I>5;I--)
{
PRINTF("HELLO");
} | 5 | 5 | How many iterations does the following loop have?
FOR (I=2;I<9;I=I+1)
{
PRINTF("HELLO");
} | 7 | 7 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<10; x++)
{
total=total + x;
if(x==5)
{
total=0;
}
} | 0 | 30 | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z > Y*Y | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
X==Y | False | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
X = Z-7 | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z = Y+8 | False | False | The volume of a cone is calculated using the formula:
TASK:
WRITE A PROGRAM TO CALCULATE THE VOLUME USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENTS FOR _R _AND _H__. _BOTH_ R _AND_ H _SHOULD BE POSITIVE NUMBERS. YOU CAN SET PI TO 3.142
PRINT THE VOLUME ON THE SCREEN TO 2 DECIMAL PLACES
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define PI (3.141592653589793)
void main()
{
float r;
float h;
//noting down inputs
printf("Hello, welcome to the cone calculator");
printf("\n\nPlease input the value of r: ");
scanf("%f", &r);
printf("\n\nExcellent, now enter the value of h ");
scanf("%f", &h);
// caculating V
float v = (PI * (r * r) * (h / 3));
//Final total
printf("Wow, your cone volume is: %.2f", v);
} | - | TASK:
PROMPT THE USER TO ENTER FIVE RAINFALL MEASUREMENTS INTO AN ARRAY (IN MILLIMETRES). (EG 3.3, 5.0, 2.6 ETC)
AFTER THE MEASUREMENTS HAVE BEEN ENTERED, PRINT EACH OF THE VALUES ON THE SCREEN USING A LOOP.
AFTER THIS, FIND THE AVERAGE OF THE RAINFALL VALUES AND PRINT THE AVERAGE ON THE SCREEN TO ONE DECIMAL PLACE.
_USE LOOPS WHERE APPROPRIATE AND ADD SUITABLE VALIDATION OF INPUTS_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void main()
{
float rainfall[5];
float average;
for (int i = 0; i < 5; i++)
{
printf("Please enter your recording of rainfall: ");
scanf(" %f", &rainfall[i]);
printf("\n");
}
for (int i = 0; i < 5; i++)
{
printf("%.2f\n", rainfall[i]);
}
average = (rainfall[0] + rainfall[1] + rainfall[2] + rainfall[3] + rainfall[4] / 4);
printf("your average of rainfall is %.2fmm", average);
} | - | TASK:
WRITE A FUNCTION CALLED _ENTERIDNUMBER() TO _ALLOW THE USER TO ENTER THE ID NUMBER (5 DIGITS) OF THREE CONFERENCE DELEGATES. THE FUNCTION SHOULD BE CALLED 3 TIMES, ONCE FOR EACH OF THE CONFERENCE DELEGATES/ THE ID NUMBER ENTERED SHOULD BE RETURNED TO THE MAIN PROGRAM.
PRINT THE ID NUMBERS ENTERED FROM THE MAIN PROGRAM, THEN CALCULATE THE TOTAL BILL FOR ATTENDING THE CONFERENCE (£65 PER PERSON) AND PRINT IT ON THE SCREEN.
INCLUDE SUITABLE VALIDATION OF INPUTS.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include "Header.h"
void main()
{
float fee = 65;
float total = (fee * 3);
enterIDNumber();
enterIDNumber();
enterIDNumber();
printf("\n the total fee for the delegates is %f");
}
\header file/
#pragma once
void enterIDNumber()
{
int ID;
int minimum = 10000;
int max = 99999;
printf("Enter next ID number: ");
scanf(" %d", &ID);
while (ID > max || ID < minimum)
{
printf("Invalid Input, Try again\n");
printf("Enter next ID number: ");
scanf(" %d", &ID);
}
return
} | - |
| Jonathan | Sharise | 2306013@student.uwtsd.ac.uk | Finished | 12 January 2024 10:20 AM | 12 January 2024 12:20 PM | 1 hour 59 mins | 53.50 | Which variable type would be most suitable to store this value?
2 | int | int | Which variable type would be most suitable to store this value?
CHRISTOPHER | char[] | string | Which variable type would be most suitable to store the following value?
56 | int | int | Which variable type would be most suitable to store this value?
67.456 | float | float | Which variable type would be most suitable to store this value?
0.004 | float | float | Which variable type would be most suitable to store this value?
G | char | char | What errors are present in the following code listing to calculate the area of a triangle? Write your answers below
1 #include <stdio.h>
2
3 void main()
4 {
5 char myname(7);
6 printf(Welcome to my program");
7
8 printf("Please enter your name: ");
9
10 scanf("%c", &myName);
11 printf("Welcome, %c", myName);
12 printf("I shall say hello to you 10 times: ")
13
14 for (x = 0; x < 9; x++);
15 {
16 printf("Hello");
17 }
18
19 } | Write your answers here (describe the errors found eg "Missing quotation mark on Line 4")
missing "CRT_SECURE_NO_WARNIGS before #include <stdio.h>
missing quotation mark on line 6
missing space on line 10 eg scanf(" %c", &myName);
the variable "myName" is typed wrong on line 10 and 11 as the declared value is myname
missing semi colon end line 12
There shouldn't be a semicolon at the end of line 14
missing 'int x;' on line 14 for the for loop | - | How many iterations does the following loop have?
FOR (I=8;I>4;I--)
{
PRINTF("HELLO");
} | 4 | 4 | How many iterations does the following loop have?
FOR (I=2;I<9;I=I+1)
{
PRINTF("HELLO");
} | 7 | 7 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<10; x++)
{
total=total + x;
if(x==5)
{
total=0;
}
} | 30 | 30 | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z = Y+8 | False | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
X==Y | False | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z > Y*Y | False | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
X*Z > X*Y | True | True | THE VOLUME OF A SQUARE-BASED PYRAMID IS CALCULATED USING THE FORMULA:
TASK:
WRITE A PROGRAM TO CALCULATE THE VOLUME USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENTS FOR _A_ AND _H__. _BOTH_ A_ AND_ H _SHOULD BE POSITIVE NUMBERS.
PRINT THE VOLUME ON THE SCREEN TO 2 DECIMAL PLACES
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
void main()
{
float a, h, vol;
printf("Please enter value for the width that is higher than zero: ");
scanf("%f", &a);
while (a < 0)
{
printf("Invalid Please try again: ");
scanf("%f", &a);
}
printf("Please enter value for the height that is higher than zero: ");
scanf("%f", &h);
while (h < 0)
{
printf("Invalid Please try again: ");
scanf("%f", &h);
}
vol = pow(a, 2) * (h / 3);
printf("%.2f", vol);
} | - | TASK:
PROMPT THE USER TO ENTER FIVE RAINFALL MEASUREMENTS INTO AN ARRAY (IN MILLIMETRES). (EG 3.3, 5.0, 2.6 ETC)
AFTER THE MEASUREMENTS HAVE BEEN ENTERED, PRINT EACH OF THE VALUES ON THE SCREEN USING A LOOP.
AFTER THIS, FIND THE AVERAGE OF THE RAINFALL VALUES AND PRINT THE AVERAGE ON THE SCREEN TO ONE DECIMAL PLACE.
_USE LOOPS WHERE APPROPRIATE AND ADD SUITABLE VALIDATION OF INPUTS_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void main()
{
float rainfall[5], average, total;
int i;
for (i = 0; i < 5; i++)
{
printf("Please enter value for rainfall measurement %d: ", i+1);
scanf("%f", &rainfall[i]);
while (rainfall[i] < 0)
{
printf("Invalid value. Please try again: ");
scanf("%f", &rainfall[i]);
}
}
printf("\nYou enetered: \n");
for (i = 0; i < 5; i++)
{
printf("%d. %.2f\n", i+1, rainfall[i]);
}
total = rainfall[0] + rainfall[1] + rainfall[2] + rainfall[3] + rainfall[4];
average = total / 5;
printf("The average of rainfall is %.1f", average);
} | - | TASK:
Write a function called _enterphone() to _allow the user to enter some UK office extension numbers (4 digits). The function should be called 3 times, and one number entered each time. Return the number entered back to the main program.
Print the numbers from the main program, then calculate and print the total cost of installation (£12.99 per number)
Include suitable validation of inputs.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include "Header.h"
void main()
{
int extNum1, extNum2, extNum3;
float cost;
extNum1 = enterphone();
extNum2 = enterphone();
extNum3 = enterphone();
printf("\n\nThe extension numbers you entered were: %d %d %d", extNum1, extNum2, extNum3);
cost = 12.99 * 3;
printf("\nTotal due is: \x9c%.2f", cost);
}
========================================================================================================================================
Header File
#pragma once
int enterphone()
{
int num;
printf("Please enter extension number: ");
scanf("%d", &num);
while (num < 1000 || num > 9999)
{
printf("Invalid. Only input 4 digits");
scanf("%4d", &num);
}
return num;
} | - |
| Gibson | Teifion | 2304294@student.uwtsd.ac.uk | Finished | 12 January 2024 10:21 AM | 12 January 2024 12:24 PM | 2 hours 3 mins | 56.00 | Which variable type would be most suitable to store this value?
64995 | int | int | Which variable type would be most suitable to store this value?
BERT | char | string | Which variable type would be most suitable to store the following value?
JOHN | char | string | Which variable type would be most suitable to store this value?
0.004 | float | float | Which variable type would be most suitable to store the following value?
56 | int | int | Which variable type would be most suitable to store this value?
67.456 | float | float | What errors are present in the following code listing to calculate the area of a triangle? Write your answers below
1 #include <stdio.h>
2
3 void main()
4 {
5 char myname(7);
6 printf(Welcome to my program");
7
8 printf("Please enter your name: ");
9
10 scanf("%c", &myName);
11 printf("Welcome, %c", myName);
12 printf("I shall say hello to you 10 times: ")
13
14 for (x = 0; x < 9; x++);
15 {
16 printf("Hello");
17 }
18
19 } | line 5 the array after myname should be in square brackets not round brackets additionally in line 5 the name of the varible should use camel case or underscores to make it more clear to read (for example myName/my_name) and camel case is used for the variable in the rest of the program (lines 10 and 11)
line 6 is missing a quotation mark after the ( on the print f
line 10 scanf should have %s not %c as it is storing a string
line 12 is missing a semicolon at the end of the line of code
line 14 will only output once as < is used instaid of > in the for loop. additionally, will only loop 8 times when corrected as x > 9 needs to be x > 10 finally, x has never been defined in the code, needs a int x; in the code for loop to work
| - | How many iterations does the following loop have?
FOR (I=1;I<=8;I++)
{
PRINTF("HELLO");
} | 8 iterations | 8 | How many iterations does the following loop have?
FOR (I=0;I<8;I++)
{
PRINTF("HELLO");
} | 8 iterations | 8 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<9; x++)
{
total=total+x;
if(x==5)
{
total=0;
}
} | 21 | 21 | Given the following values x=5, y=3, z=12 is the statement below true or false?
X==Y | False | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z != Y*4 | False | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
X = Z-7 | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
X*Z > X*Y | True | True | THE VOLUME OF A SPHERE IS CALCULATED USING THE FORMULA:
TASK:
WRITE A PROGRAM TO CALCULATE THE VOLUME USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENT FOR _R_. _R_ SHOULD NOT BE NEGATIVE. YOU MAY SET PI AS 3.142.
PRINT THE VOLUME ON THE SCREEN TO 2 DECIMAL PLACES.
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define PI 3.142
void main()
{
float r = 0, volume_sphere;
printf("Enter radius of sphere :");
scanf("%f", &r);
while (r <= 0)
{
printf("Please input a value above 0 :");
scanf("%f", &r);
}
volume_sphere = 1.33333333333 * PI * (r * r * r);
printf("Volume of sphere is %.2f", volume_sphere);
} | - | TASK:
PROMPT THE USER TO ENTER FIVE RAINFALL MEASUREMENTS INTO AN ARRAY (IN MILLIMETRES). (EG 3.3, 5.0, 2.6 ETC)
AFTER THE MEASUREMENTS HAVE BEEN ENTERED, PRINT EACH OF THE VALUES ON THE SCREEN USING A LOOP.
AFTER THIS, FIND THE AVERAGE OF THE RAINFALL VALUES AND PRINT THE AVERAGE ON THE SCREEN TO ONE DECIMAL PLACE.
_USE LOOPS WHERE APPROPRIATE AND ADD SUITABLE VALIDATION OF INPUTS_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void main()
{
int i;
float rainfall[5], avrage_rainfall = 0;
for (i = 0; i < 5; i++)
{
printf("Please input total rainfall (mm) for day %d :", i + 1);
scanf("%f", &rainfall[i]);
while (rainfall[i] < 0)
{
printf("Please input a positive value :");
scanf("%f", &rainfall);
}
}
for (i = 0; i < 5; i++)
{
printf("Total Rainfall for day %d was %.1fmm\n", i + 1, rainfall[1]);
avrage_rainfall = avrage_rainfall + rainfall[i];
}
avrage_rainfall = avrage_rainfall / 5;
printf("\nThe avrage rainfall is %.1fmm", avrage_rainfall);
} | - | TASK:
Write a function called _enterphone() to _allow the user to enter some UK office extension numbers (4 digits). The function should be called 3 times, and one number entered each time. Return the number entered back to the main program.
Print the numbers from the main program, then calculate and print the total cost of installation (£12.99 per number)
Include suitable validation of inputs.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int enterphone(int i)
{
int number;
printf("Enter extention number %d : ", i + 1);
scanf("%d", &number);
while (number < 1000 || number > 9999)
{
printf("Invalid extention number, enter a valid value :");
scanf("%d", &number);
}
return number;
}
void main()
{
int i, ext_num[3];
float cost = 0;
for (i = 0; i < 3; i++)
{
ext_num[i] = enterphone(i);
cost = cost + 12.99;
}
printf("The inputted extention numbers were ");
for (i = 0; i < 3; i++)
{
printf("%d, ", ext_num[i]);
}
printf("\nand the total cost will be \x9c%.2f", cost);
} | - |
| Jones | Mathew | 2317425@student.uwtsd.ac.uk | Finished | 12 January 2024 10:21 AM | 12 January 2024 12:18 PM | 1 hour 57 mins | 54.00 | Which variable type would be most suitable to store this value?
-6.23 | float | float | Which variable type would be most suitable to store this value?
4.192 | float | float | Which variable type would be most suitable to store this value?
B | char | char | Which variable type would be most suitable to store this value?
64995 | int | int | Which variable type would be most suitable to store this value?
CHRISTOPHER | char[], string, char array | string | Which variable type would be most suitable to store this value?
-26.1 | float | float | What errors are present in the following code listing to calculate the area of a room? Write your answers below
1 #include <stdio.h>
2
3 void main()
4 {
5 float widthRoom, heightRoom, total;
6 printf("Enter width: );
7 scanf("%d", &widthRoom);
8 printf("Enter height: ")
9 scanf("%d", &heightroom);
10 total = baseRoom / heightRoom;
11
12 print("The area of the room is", total);
13 } | Write your answers here (describe the errors found eg "Missing quotation mark on Line 4")
Line 6 is missing a quotation mark at the end.
Line 7 scanf has %d but should be using %f as it is a float.
Line 8 is missing a semi colon at the end.
Line 9 scanf has %d but should be using %f as it is a float.
Line 9 heightRoom has not got a capital R.
Line 10 has used baseRoom. This should be widthRoom
Line 10 is using / which is used for divison and should be * which is for multiplication.
Line 12 is missing %f at the end of " The area of the room is %f". | - | How many iterations does the following loop have?
FOR (I=8;I>4;I--)
{
PRINTF("HELLO");
} | 4 | 4 | How many iterations does the following loop have?
FOR (I=0;I<8;I++)
{
PRINTF("HELLO");
} | 8 | 8 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<8; x++)
{
total=total + x;
if(x==5)
{
total=0;
}
} | 13 | 13 | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z = Y*4 | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z > Y*Y | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
X = Z-7 | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z = Y+8 | False | False | THE SURFACE AREA OF A SPHERE IS CALCULATED USING THE FORMULA:
TASK:
WRITE A PROGRAM TO CALCULATE THE SURFACE AREA USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENT FOR _R__. R _SHOULD BE A POSITIVE NUMBER. YOU CAN SET PI TO 3.142.
PRINT THE AREA ON THE SCREEN TO 2 DECIMAL PLACES
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #include <stdio.h>
#define PI 3.14
void main()
{
float area, radius;
printf("Please enter your radius: ");
scanf("%f", &radius);
while (radius < 0)
{
printf("Please enter a positive number: ");
scanf("%f", &radius);
}
if (radius >= 0)
{
printf("\nThank you.\n\n");
}
area = 4 * PI * (radius * radius);
printf("The area of the sphere is %.2f.", area);
} | - | TASK:
A SALESMAN WANTS TO CALCULATE THE NUMBER OF MILES HE HAS COVERED IN THE LAST WORKING WEEK (MONDAY TO FRIDAY), AND ALSO THE NEW TOTAL MILEAGE FOR HIS CAR WHICH WAS 8600 MILES AT THE BEGINNING OF THE WEEK.
1. PROMPT THE USER TO ENTER THE FIVE MILEAGE FIGURES FOR THE WEEK INTO AN ARRAY.
2. PRINT EACH OF THE MILEAGE FIGURES ON THE SCREEN.
3. CALCULATE THE TOTAL MILEAGE FOR THE WEEK.
4. CALCULATE THE NEW MILEAGE FOR THE CAR (IT WAS 8600 AT THE START OF THE WEEK)
_USE LOOPS WHERE APPROPRIATE_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | #include <stdio.h>
void main()
{
int mileage[5];
int total, car_total = 8600;
printf("\nPlease enter your mileage. ");
for (int i = 0; i < 5; i++)
{
printf("\n\nMileage for day %d: ", i + 1);
scanf("%d", &mileage[i]);
printf("\nYour mileage was %d", mileage[i]);
while (mileage[i] < 0)
{
printf("\n\nPlease enter a positive number: ");
scanf("%d", &mileage[i]);
}
}
total = mileage[0] + mileage[1] + mileage[2] + mileage[3] + mileage[4];
printf("\n\nThe total mileage for the week is %d", total);
car_total = car_total + total;
printf("\n\nYour cars new mileage is %d", car_total);
} | - | TASK:
Write a function called _enterphone() to _allow the user to enter some UK office extension numbers (4 digits). The function should be called 3 times, and one number entered each time. Return the number entered back to the main program.
Print the numbers from the main program, then calculate and print the total cost of installation (£12.99 per number)
Include suitable validation of inputs.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include "Header.h"
int main()
{
int number1, number2, number3;
number1 = enterphone();
number2 = enterphone();
number3 = enterphone);
printf("\nThe extension numbers entered were: %d %d %d", number1, number2, number3);
float price = 12.99 * 3;
printf("\n\nThe total due is \x9c%.2f", price);
}
#pragma once
int enterphone()
{
int phone;
printf("Enter next extension number: ");
scanf("%d", &phone);
return phone;
} | - |
| Oliver | William Baker | 2314716@student.uwtsd.ac.uk | Finished | 12 January 2024 10:21 AM | 12 January 2024 11:10 AM | 48 mins 49 secs | 52.00 | Which variable type would be most suitable to store this value?
-6.23 | Float | float | Which variable type would be most suitable to store this value?
64995 | Int | int | Which variable type would be most suitable to store this value?
CHRISTOPHER | String | string | Which variable type would be most suitable to store the following value?
56 | Int | int | Which variable type would be most suitable to store this value?
4.192 | Float | float | Which variable type would be most suitable to store this value?
G | Char | char | What errors are present in the following code listing to calculate the area of a triangle? Write your answers below
1 #include <stdio.h>
2
3 void main()
4 {
5 char myname(7);
6 printf(Welcome to my program");
7
8 printf("Please enter your name: ");
9
10 scanf("%c", &myName);
11 printf("Welcome, %c", myName);
12 printf("I shall say hello to you 10 times: ")
13
14 for (x = 0; x < 9; x++);
15 {
16 printf("Hello");
17 }
18
19 } | Write your answers here (describe the errors found eg "Missing quotation mark on Line 4")
Line 5: brackets should be [7] instead of (7)
Line 6: print if statement is quotation marks at the beginning, should be - printf("Welcome to my program")
line 10: scanf should be accepting "%s" instead of "%c", as c is for only one char instead of a whole string
line 12: semi colon missing at the end of printf statement, should be after the brackets
line 14: semi colon shouldn't be at the end of the line | - | How many iterations does the following loop have?
FOR (I=0;I<8;I++)
{
PRINTF("HELLO");
} | 8 | 8 | How many iterations does the following loop have?
FOR (I=1;I<=8;I++)
{
PRINTF("HELLO");
} | 7 | 8 | What is the value of the integer variable _total_ after the following code is executed?
total=1;
for (x=0; x<10; x++)
{
total=total + x;
if(x==5)
{
total=0;
}
} | 40 | 30 | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z > Y*Y | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z != Y*4 | False | False | Given the following values x=5, y=3, z=12 is the statement below true or false?
X = Z-7 | True | True | Given the following values x=5, y=3, z=12 is the statement below true or false?
Z = Y+8 | False | False | THE SURFACE AREA OF A SPHERE IS CALCULATED USING THE FORMULA:
TASK:
WRITE A PROGRAM TO CALCULATE THE SURFACE AREA USING THE ABOVE FORMULA.
ALLOW THE USER TO ENTER THE MEASUREMENT FOR _R__. R _SHOULD BE A POSITIVE NUMBER. YOU CAN SET PI TO 3.142.
PRINT THE AREA ON THE SCREEN TO 2 DECIMAL PLACES
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/) _
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
void calculateSphereSurface(void);
void main()
{
calculateSphereSurface();
}
void calculateSphereSurface()
{
const float pi = 3.142;
float sphereRadius, finalAnswer;
bool hasEnteredRadius = true;
printf("Please enter the radius of the sphere.\n");
scanf("%f", &sphereRadius);
if (sphereRadius <= 0)
{
printf("Sorry, that isnt valid. Please try again.\n");
hasEnteredRadius = false;
}
else
{
printf("Radius accepted.\n");
}
while (!hasEnteredRadius)
{
printf("Please enter the radius of the sphere.\n");
scanf("%f", &sphereRadius);
if (sphereRadius < 0)
{
printf("Sorry, that isnt valid. Please try again.\n");
}
else
{
printf("Radius accepted.\n");
hasEnteredRadius = true;
}
}
finalAnswer = 4 * pi * pow(sphereRadius, 2);
printf("Your final answer, the surface of the sphere, is %.2f.\n", finalAnswer);
} | - | TASK:
A SALESMAN WANTS TO CALCULATE THE NUMBER OF MILES HE HAS COVERED IN THE LAST WORKING WEEK (MONDAY TO FRIDAY), AND ALSO THE NEW TOTAL MILEAGE FOR HIS CAR WHICH WAS 8600 MILES AT THE BEGINNING OF THE WEEK.
1. PROMPT THE USER TO ENTER THE FIVE MILEAGE FIGURES FOR THE WEEK INTO AN ARRAY.
2. PRINT EACH OF THE MILEAGE FIGURES ON THE SCREEN.
3. CALCULATE THE TOTAL MILEAGE FOR THE WEEK.
4. CALCULATE THE NEW MILEAGE FOR THE CAR (IT WAS 8600 AT THE START OF THE WEEK)
_USE LOOPS WHERE APPROPRIATE_
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission._ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
void calculateMileage(void);
void main()
{
calculateMileage();
}
void calculateMileage()
{
int mileageFigures[5], totalMileage = 0;
const int previousMileage = 8600;
for (int i = 0; i < 5; i++)
{
printf("Please enter the mileage for week %d.\n", i + 1);
scanf("%d", &mileageFigures[i]);
totalMileage += mileageFigures[i];
}
for (int i = 0; i < 5; i++)
{
printf("Week %d: Car Mileage was %d.\n", i + 1, mileageFigures[i]);
}
printf("\nTotal mileage for the week was %d.\n\n", totalMileage);
totalMileage += previousMileage;
printf("Adding on the previous mileage, %d, the total mileage this car has done is %d.", previousMileage, totalMileage);
} | - | TASK:
WRITE A FUNCTION CALLED _ENTERIDNUMBER() TO _ALLOW THE USER TO ENTER THE ID NUMBER (5 DIGITS) OF THREE CONFERENCE DELEGATES. THE FUNCTION SHOULD BE CALLED 3 TIMES, ONCE FOR EACH OF THE CONFERENCE DELEGATES/ THE ID NUMBER ENTERED SHOULD BE RETURNED TO THE MAIN PROGRAM.
PRINT THE ID NUMBERS ENTERED FROM THE MAIN PROGRAM, THEN CALCULATE THE TOTAL BILL FOR ATTENDING THE CONFERENCE (£65 PER PERSON) AND PRINT IT ON THE SCREEN.
INCLUDE SUITABLE VALIDATION OF INPUTS.
Sample output:
_Write your program using Visual Studio or similar (or the online C compiler at https://www.onlinegdb.com/)_
_Copy and paste your code into the box below for submission. (If you are using multiple files for your code, simply copy and paste them one under the other.)_ | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include "id.h"
void delegateID(void);
void main()
{
delegateID();
}
void delegateID()
{
int delegateIDNumber[3] = { 0,0,0 };
float totalBill = 0;
for (int i = 0; i < 3; i++)
{
delegateIDNumber[i] += enteridnumber();
totalBill += 65.00;
}
for (int i = 0; i < 3; i++)
{
printf("Delegate number %ds ID Number is %d.\n",i+1, delegateIDNumber[i]);
}
printf("\nThe total bill is \x9c%.2f.", totalBill);
}
For id.h:
#pragma once
int enteridnumber()
{
bool hasEnteredNumber = true;
int idNumber;
printf("Please enter the ID number.\n");
scanf("%d", &idNumber);
if (idNumber <= 9999 || idNumber > 99999)
{
printf("That isnt a valid number. Please try again.\n");
hasEnteredNumber = false;
}
else
{
printf("ID number accepted.\n");
return idNumber;
}
while (!hasEnteredNumber)
{
printf("Please enter the ID number.\n");
scanf("%d", &idNumber);
if (idNumber <= 9999 || idNumber > 99999)
{
printf("That isnt a valid number. Please try again.\n");
}
else
{
printf("ID number accepted.\n");
hasEnteredNumber = true;
return idNumber;
}
}
} | - |